<template>
  <el-dialog title="用户注册" width="600px" center :visible.sync="isShow">
    <el-form class="form" label-width="100px">
      <el-form-item label="头像">
        <el-upload
          class="avatar-uploader"
          :action="imageUrl"
          :show-file-list="false"
          :on-success="handleAvatarSuccess"
          :before-upload="beforeAvatarUpload"
        >
          <img v-if="imageUrl" :src="imageUrl" class="avatar" />
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
      </el-form-item>
      <el-form-item label="昵称">
        <el-input type="text"></el-input>
      </el-form-item>
      <el-form-item label="邮箱">
        <el-input type="text"></el-input>
      </el-form-item>
      <el-form-item label="手机">
        <el-input type="text"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input type="text"></el-input>
      </el-form-item>
      <el-form-item label="图形码">
        <div class="codAll">
          <el-input class="cod" type="text"></el-input>
          <img
            class="img"
            src="http://119.91.150.211:8080/heimamm/public/captcha?type=login"
            alt=""
          />
        </div>
      </el-form-item>
      <el-form-item label="验证码">
        <div class="authAll">
          <el-input class="auth" type="text"></el-input>
          <span class="auth1">获取用户验证码</span>
        </div>
      </el-form-item>
    </el-form>

    <template #footer>
      <div style="text-align: center">
        <el-button>取消</el-button>
        <el-button type="primary">确定</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
export default {
  data () {
    return {
      isShow: false,
      imageUrl: 'http://119.91.150.211:8080/heimamm/public/uploads?image=',
      form: {
        username: '', //	是	string	用户名
        email: '', //是	string	邮箱
        phone: '', //	是	string	手机号
        password: '', //	是	string	密码
        avatar: '', //	是	string	头像地址
        rcode: '' //是	string	验证码
      }
    }
  },
  methods: {
    handleAvatarSuccess (res, file) {
      this.imageUrl += file.name
      console.log(res)
      console.log(file)
    },
    beforeAvatarUpload (file) {
      // const isJPG = file.type === 'image/jpeg'
      const isPNG = file.type === 'image/png'
      const isLt2M = file.size / 1024 / 1024 < 2

      if (!isPNG) {
        this.$message.error('上传头像图片只能是 JPG或者PNG 格式!')
      }
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!')
      }
      return isPNG && isLt2M
    }
  }
}
</script>

<style lang="scss" scoped>
.form {
  .codAll {
    display: flex;
    align-items: center;
    .img {
      width: 140px;
      height: 100%;
      margin-left: 10px;
    }
    .cod {
      width: 300px;
    }
  }
  .authAll {
    display: flex;
    .auth {
      width: 300px;
    }
    .auth1 {
      border: 1px solid #ccc;
      padding: 0px 17px;
      border-radius: 7px;
      margin-left: 10px;
    }
  }
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409eff;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
    border: 1px dashed #ccc;
    margin-left: 120px;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
}
</style>
